20. Particle Weights Solution

We can calculate particle weights using the following equation:

P(x,y) =\frac{1}{2\pi \sigma\_{x}\sigma\_{y}}e^{-(\frac{(x-\mu_x)^2}{2\sigma_x^2}+\frac{(y-\mu_y)^2}{2\sigma_y^2})}
  • Recall that for this example the standard deviation for both x and y is 0.3.
  • x and y are the observations in map coordinates from landmarks quiz and \mu_x, \mu_y are the coordinates of the nearest landmarks. These should correspond to the correct responses from previous quizzes.

Quiz Solutions

The solutions are implemented in python for clarity.

OBS1 Multivariate-Gaussian Probability

import math

# define inputs
sig_x= 0.3
sig_y= 0.3
x_obs= 6
y_obs= 3
mu_x= 5
mu_y= 3

# calculate normalization term
gauss_norm= (1/(2 * np.pi * sig_x * sig_y))

# calculate exponent
exponent= ((x_obs - mu_x)**2)/(2 * sig_x**2) + ((y_obs - mu_y)**2)/(2 * sig_y**2)

# calculate weight using normalization terms and exponent
weight= gauss_norm * math.exp(-exponent)

print(weight) # should be around 0.00683644777551 rounding to 6.84E-3

OBS2 Multivariate-Gaussian Probability

import math

# define inputs
sig_x= 0.3
sig_y= 0.3
x_obs= 2
y_obs= 2
mu_x= 2
mu_y= 1

# calculate normalization term
gauss_norm= (1/(2 * np.pi * sig_x * sig_y))

# calculate exponent
exponent= ((x_obs - mu_x)**2)/(2 * sig_x**2) + ((y_obs - mu_y)**2)/(2 * sig_y**2)

# calculate weight using normalization terms and exponent
weight= gauss_norm * math.exp(-exponent)

print(weight) # should be around 0.00683644777551 rounding to 6.84E-3

OBS3 Multivariate-Gaussian Probability

import math

# define inputs
sig_x= 0.3
sig_y= 0.3
x_obs= 0
y_obs= 5
mu_x= 2
mu_y= 1

# calculate normalization term
gauss_norm= (1/(2 * np.pi * sig_x * sig_y))

# calculate exponent
exponent= ((x_obs - mu_x)**2)/(2 * sig_x**2) + ((y_obs - mu_y)**2)/(2 * sig_y**2)

# calculate weight using normalization terms and exponent
weight= gauss_norm * math.exp(-exponent)

print(weight) # should be around 9.83184874151e-49 rounding to 9.83E-49

Particle's Final Weight

To get the final weight just multiply all the calculated measurement probabilities together.

9.83184874151e-49 * 0.00683644777551 * 0.00683644777551= 4.59112934464959e-53 
# 4.60E-53